package com.central.user.util;

import org.apache.ibatis.jdbc.Null;
import org.apache.poi.ss.formula.functions.T;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StringUtil {

    public static List<Integer> stringToList(String s){
        List<Integer> list = new ArrayList<>();
        s = s.substring(1,s.length()-1);
        if (s == null || s == ""){
            return null;
        }

        String[] strs = s.split(",");
        for (int i = 0; i < strs.length; i++){
            strs[i].trim();
            if (strs[i] != null && strs[i] != ""){
                list.add(Integer.parseInt(strs[i]));
            }
        }
        return list;
    }

    /**
     * 取key值
     * @param map 文本格式 == "{1:1,2:2}"
     * @return
     */
    public static List<Integer> stringToListByMapKey(String map){
        List<Integer> list = new ArrayList<>();
        map = map.substring(1,map.length()-1);
        if (map == null || map == ""){
            return null;
        }
        String[] strs = map.split(",");
        for (String keyAndVal : strs){
            String[] strings = keyAndVal.split(":");
            list.add(Integer.parseInt(strings[0]));
        }
        return list;
    }

    public static List<Integer> stringToListByMapVal(String s){
        List<Integer> list = new ArrayList<>();
        return list;
    }

    /**
     *
     * @param s 文本格式 == "{1:1,2:2}"
     * @return
     */
    public static Map<Integer,Integer> stringToMapByKeyAndValIsInteger(String s){
        Map<Integer,Integer> map = new HashMap<>();
        return map;
    }
}
